package com.pure.common.lambda.showtime;

import com.pure.common.lambda.TestInterfaceI;
import com.pure.common.lambda.model.SAPCustomerReq;

import java.lang.reflect.Field;
import java.util.function.Predicate;

/**
 * @description: lambda learn
 * @author: Jeffrey
 * @created: 2022-05-09 22:26
 **/
public class LambdaLearn {

    public static void main(String[] args) {


//        SAPCustomerReq.BODYDTO body = new SAPCustomerReq.BODYDTO();
//        body.setVkorg("5001");
//        System.out.println(body.toString());
//        SAPCustomerReq.BODYDTO noNullBody = noNullStringAttr(body);
//        System.out.println(noNullBody.toString());

        k(() -> System.out.println("ddadadad"));


    }

    private static void k(TestInterfaceI testInterfaceI) {

        testInterfaceI.testMethod();
    }

    public static <T> T noNullStringAttr(T cls) {
        Field[] fields = cls.getClass().getDeclaredFields();
        if (fields == null || fields.length == 0) {
            return cls;
        }
        for (Field field : fields) {
            if ("String".equals(field.getType().getSimpleName())) {
                field.setAccessible(true);
                try {
                    Object value = field.get(cls);
                    if (value == null) {
                        field.set(cls, "");
                    }
                } catch (IllegalArgumentException | IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
        return cls;
    }

}
